import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

import departmentsAsyncRoute from '@/router/modules/departments'
import employeesAsyncRoute from '@/router/modules/employees'
import settingsAsyncRoute from '@/router/modules/settings'
import salarysAsyncRoute from '@/router/modules/salarys'
// import socialAsyncRoute from '@/router/modules/social'
import socialAsyncRouter from '@/router/modules/social_securitys'
import attendancesAsyncRoute from '@/router/modules/attendances'
import approvalsAsyncRoute from '@/router/modules/approvals'
import permissionsAsyncRoute from '@/router/modules/permissions'

export const asyncRoutes = [
  departmentsAsyncRoute,
  settingsAsyncRoute,
  employeesAsyncRoute,
  permissionsAsyncRoute,
  approvalsAsyncRoute,
  attendancesAsyncRoute,
  salarysAsyncRoute,
  socialAsyncRouter
]

// 静态路由表 不要权限
export const constantRoutes = [
  // {
  //   path: '/demo',
  //   component: () => import('@/views/demo/native/index.vue'),
  //   hidden: true
  // },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/import',
    component: () => import('@/views/import/index.vue'),
    hidden: true
  },
  // {
  //   path: '/404',
  //   component: () => import('@/views/404'),
  //   hidden: true
  // },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  }
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes] // 将动态路由表和静态路由表合并一起生成最终的路由表
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
